var t = require("../../@babel/runtime/helpers/interopRequireDefault").default, e = t(require("../../kta/index")), a = t(require("../../api/api_YQYL.js")), i = t(require("../../api/auth")), o = require("../../config/Links"), n = require("../../utils/YQYL"), s = 1, r = {
    "-1": "illegal",
    1: "order",
    2: "active",
    3: "charge",
    4: "receive"
}, c = getApp();

e.default.Page({
    data: {
        options: {},
        height: 1100,
        activity_info: {},
        shareUrl: "",
        imgBaseUrl: o.imageBaseUrl.YQYL_new,
        imgBaseUrl2: o.imageBaseUrl.YQYL2,
        tabIndex: "1",
        invite_record_list: [],
        showList: [],
        red_packet_daily_limit: !1,
        showModal: !1,
        modal: !1,
        cancelText: "",
        modalText: "",
        time: 0,
        showPoster: !1,
        poster: null,
        postUtil: {
            handleSharePoster: function() {}
        }
    },
    onShareAppMessage: function() {
        return (0, n.handleShare)(this, "record18");
    },
    onLoad: function(t) {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    height: t.windowHeight - 80
                });
            }
        }), this.setData({
            options: t
        });
    },
    onShow: function() {
        this.fetchList();
    },
    filterTab: function(t) {
        var e = this.data.tabIndex;
        return "1" === e ? 1 === t || 2 === t : "2" === e ? 3 === t || 4 === t : "3" === e && -1 === t;
    },
    fetchList: function() {
        var t = this;
        wx.showLoading({
            title: "加载中"
        }), (0, n.initPage)(this, this.data.options, "record18").then(function(e) {
            var a = e.inviteRecordList.filter(function(e) {
                return t.filterTab(e.status);
            });
            a.forEach(function(t) {
                t.invitee_phone = t.inviteePhone, t.status = r[t.status];
            }), t.setData({
                invite_record_list: a,
                showList: a.slice(0, 10 * s)
            });
        });
    },
    loadMore: function() {
        10 * s < this.data.invite_record_list.length && (s++, this.setData({
            showList: this.data.invite_record_list.slice(0, 10 * s)
        }));
    },
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    changeTab: function(t) {
        var e = this, a = t.currentTarget.dataset.index;
        c.kta.clickStat([ null, "524c8261405e4a2eb840b26a8338ee2c", "a2c7dbe1c5c1434197a45c98e52b82aa", "48883767913d46289cbe2d87f4cb1d0b" ][a]), 
        s = 1, this.setData({
            tabIndex: a
        }, function() {
            e.fetchList();
        });
    },
    handlePoster: function() {
        this.data.poster ? this.setData({
            showPoster: !0
        }) : this.data.postUtil.handleSharePoster();
    },
    showModal: function(t) {
        var e = this, i = t.currentTarget.dataset, o = i.type, n = i.err;
        if ("order" === o || "active" === o) wx.showToast({
            title: "好友未完成首充，暂不可领取红包！",
            icon: "none",
            duration: 2e3
        }); else if ("illegal" === o) wx.showModal({
            content: n || "订单信息发生变更，无法领取红包，敬请谅解",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("illegal2" === o) wx.showModal({
            content: "微信红包发放后的24小时内未领取。已超时退回",
            showCancel: !1,
            confirmText: "确定"
        }); else if (this.data.red_packet_daily_limit) wx.showModal({
            content: "单用户单日领取红包个数限额10个，请于次日领取",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("charge" === o) {
            var s = t.currentTarget.dataset.seq;
            this.checkValid() && (c.kta.clickStat("1ac6f8be3b05467a9ed776469de9477d"), a.default.getHongBao18(s).then(function() {
                wx.showModal({
                    content: "红包将通过“王卡助手”微信公众号发放，请您留意公众号消息",
                    showCancel: !1,
                    confirmText: "知道啦"
                }), e.fetchList();
            }).catch(function(t) {
                "36000" === t.code ? wx.navigateTo({
                    url: "/pages/YQYL_register/index?adtag=" + c.globalData.aucChannel
                }) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                });
            }));
        }
    },
    checkValid: function() {
        return !!c.globalData.phone || (this.setData({
            modal: !0,
            modalText: "手机号码获取失败，无法领取红包!",
            modalType: "phone"
        }), !1);
    },
    getPhoneNumber: function(t) {
        this.setData({
            modal: !1,
            modalText: "",
            modalType: ""
        }), i.default.auth({
            encryptedData: t.detail.encryptedData,
            iv: t.detail.iv,
            source: 2
        }).then(function(t) {
            c.globalData.phone = t.data.phone, wx.navigateTo({
                url: "/pages/YQYL_register/index?channel=".concat(c.globalData.aucChannel, "&adtag=").concat(c.globalData.aucChannel)
            });
        });
    },
    closeModal: function() {
        this.setData({
            modal: !1,
            showModal: !1,
            modalText: ""
        });
    },
    closePoster: function() {
        this.setData({
            showPoster: !1
        });
    },
    toOldRecordPage: function() {
        wx.navigateTo({
            url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/KCard/wxCommon/goto?state=WZJH_RECOMMEND_URL"))
        });
    },
    copyKeyword: function() {
        wx.setClipboardData({
            data: "我的历史邀请记录"
        }), this.closeModal();
    }
});